package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.TmcUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OneClickReport;
import com.ruoyi.system.service.IOneClickReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一键上报Controller
 * 
 * @author ruoyi
 * @date 2021-07-01
 */
@RestController
@RequestMapping("/system/oneClickReport")
public class OneClickReportController extends BaseController
{
    @Autowired
    private IOneClickReportService oneClickReportService;

    /**
     * 查询一键上报列表
     */
//    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(OneClickReport oneClickReport)
    {
        startPage();
        List<OneClickReport> list = oneClickReportService.selectOneClickReportList(oneClickReport);
        return getDataTable(list);
    }

    /**
     * 导出一键上报列表
     */
//    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "一键上报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OneClickReport oneClickReport)
    {
        List<OneClickReport> list = oneClickReportService.selectOneClickReportList(oneClickReport);
        ExcelUtil<OneClickReport> util = new ExcelUtil<OneClickReport>(OneClickReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 获取一键上报详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{oId}")
    public AjaxResult getInfo(@PathVariable("oId") Long oId)
    {
        return AjaxResult.success(oneClickReportService.selectOneClickReportById(oId));
    }

    /**
     * 新增一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "一键上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OneClickReport oneClickReport)

    {
        int i1 = oneClickReportService.insertOneClickReport(oneClickReport);
//        获取家人联系方式发东西
        List<TmcUser> quweyfamily = oneClickReportService.quweyfamily(oneClickReport.getPublicuserId());
//发短信或回应
        for (int i = 0; i <quweyfamily.size() ; i++) {

        }
        return toAjax(i1);
    }

    /**
     * 修改一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "一键上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OneClickReport oneClickReport)
    {
        return toAjax(oneClickReportService.updateOneClickReport(oneClickReport));
    }

    /**
     * 删除一键上报
     */
//    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "一键上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{oIds}")
    public AjaxResult remove(@PathVariable Long[] oIds)
    {
        return toAjax(oneClickReportService.deleteOneClickReportByIds(oIds));
    }
}
